package com.rc.saas.tenant.service.elec;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.BaseSearch;
import com.rc.saas.tenant.common.utils.BeanUtil;
import com.rc.saas.tenant.mapper.area.PlatformProvinceMapper;
import com.rc.saas.tenant.mapper.elec.ElecStationMapper;
import com.rc.saas.tenant.mapper.hlht.HlhtTenantOpenStationMapper;
import com.rc.saas.tenant.mapper.tenant.TenantMapper;
import com.rc.saas.tenant.mapper.ticket.TenantTicketStationMapper;
import com.rc.saas.tenant.model.area.PlatformProvince;
import com.rc.saas.tenant.model.elec.ElecGun;
import com.rc.saas.tenant.model.elec.ElecPile;
import com.rc.saas.tenant.model.elec.ElecStation;
import com.rc.saas.tenant.model.elec.ElecStationExample;
import com.rc.saas.tenant.model.hlht.HlhtTenantOpen;
import com.rc.saas.tenant.model.hlht.HlhtTenantOpenStation;
import com.rc.saas.tenant.model.hlht.HlhtTenantOpenStationExample;
import com.rc.saas.tenant.model.tenant.Tenant;
import com.rc.saas.tenant.model.tenant.TenantSetting;
import com.rc.saas.tenant.model.ticket.TenantTicketStation;
import com.rc.saas.tenant.model.ticket.TenantTicketStationExample;
import com.rc.saas.tenant.search.StatisticsSearch;
import com.rc.saas.tenant.search.elec.ElecSationSearch;
import com.rc.saas.tenant.search.elec.StationHlhtTenantOpenSearch;
import com.rc.saas.tenant.search.hlht.HlhtTenantOpenStationSearch;
import com.rc.saas.tenant.service.hlht.HlhtOperatorService;
import com.rc.saas.tenant.service.hlht.HlhtTenantOpenService;
import com.rc.saas.tenant.service.tenant.TenantRoleService;
import com.rc.saas.tenant.service.tenant.TenantSettingService;
import com.rc.saas.tenant.vo.elec.*;
import com.rc.saas.tenant.vo.hlht.HlhtTenantOpenStationExportVo;
import com.rc.saas.tenant.vo.hlht.HlhtTenantOpenStationVo;
import com.rc.saas.tenant.vo.hlht.StationHlhtTenantOpenVo;
import com.rc.saas.tenant.vo.invoice.InvoiceProxyStationSearchVo;
import com.rc.saas.tenant.vo.tenant.TenantUserRoleVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.*;

/**
 * Created by sven on 2018-04-17
 */
@Service
public class ElecStationServiceImpl implements ElecStationService {

    @Autowired
    private TenantMapper tenantMapper;

    @Autowired
    private ElecStationMapper elecStationMapper;

    @Autowired
    @Lazy
    private ElecPileService elecPileService;

    @Autowired
    private ElecGunService elecGunService;

    @Autowired
    private PlatformProvinceMapper platformProvinceMapper;

    @Autowired
    private HlhtTenantOpenStationMapper hlhtTenantOpenStationMapper;

    @Autowired
    private TenantTicketStationMapper tenantTicketStationMapper;

    @Autowired
    private HlhtOperatorService hlhtOperatorService;

    @Autowired
    private TenantSettingService tenantSettingService;

    @Autowired
    private HlhtTenantOpenService hlhtTenantOpenService;


    @Autowired
    private TenantRoleService tenantRoleService;

    @Override
    public ElecStationMapper getMapper() {
        return elecStationMapper;
    }

    @Override
    public PageInfo<ElecStationResult> listPageByCondition(ElecSationSearch elecSationSearchVo) {
        dealRole(elecSationSearchVo);
        PageHelper.startPage(elecSationSearchVo.getOffset(), elecSationSearchVo.getLimit());
        List<ElecStationResult> elecStationList = elecStationMapper.listPageByCondition(elecSationSearchVo);
        return new PageInfo<ElecStationResult>(elecStationList);
    }

    @Override
    public List<ElecStation> listAllStationByTenantCode(String tenantCode) {
        ElecStationExample example = new ElecStationExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andHlhtOperatorIdIsNull();
        List<ElecStation> elecStations = elecStationMapper.selectByExample(example);
        return elecStations;
    }

    public void dealRole(ElecSationSearch elecSationSearchVo){
        TenantUserRoleVo userRoleVo = tenantRoleService.getLonginRole(elecSationSearchVo.getLoginName());
        if (userRoleVo!=null){
            elecSationSearchVo.setRoleType(userRoleVo.getRoleType());
            elecSationSearchVo.setDataAuth(userRoleVo.getDataAuth());
            switch (userRoleVo.getRoleType()){
                case "1"://自定义用户
                    elecSationSearchVo.setOperatorIds(
                            StringUtils.isNotBlank(userRoleVo.getOperatorIds())?
                                    Arrays.asList(userRoleVo.getOperatorIds().split(","))
                                    :new ArrayList<String>());
                    elecSationSearchVo.setEnterpriseIds(
                            StringUtils.isNotBlank(userRoleVo.getEnterpriseIds())?
                                    Arrays.asList(userRoleVo.getEnterpriseIds().split(","))
                                    :new ArrayList<String>());
                    break;
                case "2"://加盟商用户
                    elecSationSearchVo.setOperatorIds(StringUtils.isNotBlank(userRoleVo.getOperatorIds())?
                            Arrays.asList(userRoleVo.getOperatorIds().split(","))
                            :new ArrayList<String>());
                    break;
                case "3"://企业用户
                    elecSationSearchVo.setEnterpriseIds(StringUtils.isNotBlank(userRoleVo.getEnterpriseIds())?
                            Arrays.asList(userRoleVo.getEnterpriseIds().split(","))
                            :new ArrayList<String>());
                    break;
            }
        }
    }


    @Override
    public List<ElecStation> listAllStationAndHlht(String tenantCode, Long ticketTypeId) {

        List<ElecStation> elecStations = elecStationMapper.listStationByHlhtOperatorId(null, null);

        if (ticketTypeId != null) {
            TenantTicketStationExample tenantTicketStationExample = new TenantTicketStationExample();
            tenantTicketStationExample.createCriteria().andTicketTypeIdEqualTo(ticketTypeId);
            //已经被选的桩群
            List<TenantTicketStation> tenantTicketStations = tenantTicketStationMapper.selectByExample(tenantTicketStationExample);

            for (ElecStation elecStation : elecStations) {
                elecStation.setSelect("1");
                for (TenantTicketStation tenantTicketStation : tenantTicketStations) {
                    if (elecStation.getElecStationId().equals(tenantTicketStation.getElecStationId())) {
                        elecStation.setSelect("0");
                    }
                }
            }
        }

        return elecStations;
    }

    @Override
    public Map<String, List<ElecStation>> listTicketStationHlht(String tenantCode, Long ticketTypeId) {

        Map<String, List<ElecStation>> map = new HashMap<>();


        //所有互联互通桩群
        HlhtTenantOpenStationExample example = new HlhtTenantOpenStationExample();
        example.createCriteria().andHlhtTenantCodeEqualTo(tenantCode);
        List<HlhtTenantOpenStation> hlhtTenantOpenStations = hlhtTenantOpenStationMapper.selectByExample(example);

        if (ticketTypeId != null) {
            TenantTicketStationExample tenantTicketStationExample = new TenantTicketStationExample();
            tenantTicketStationExample.createCriteria().andTicketTypeIdEqualTo(ticketTypeId);
            //已经被选的桩群
            List<TenantTicketStation> tenantTicketStations = tenantTicketStationMapper.selectByExample(tenantTicketStationExample);
            if (!CollectionUtils.isEmpty(hlhtTenantOpenStations)) {
                for (HlhtTenantOpenStation hlhtTenantOpenStation : hlhtTenantOpenStations) {
                    Long elecStationId = hlhtTenantOpenStation.getElecStationId();
                    ElecStation elecStation = elecStationMapper.selectByPrimaryKey(elecStationId);
                    Tenant tenant = tenantMapper.selectByPrimaryKey(elecStation.getTenantCode());
                    elecStation.setTenantName(tenant.getTenantName());
                    elecStation.setSelect("1");
                    for (TenantTicketStation tenantTicketStation : tenantTicketStations) {
                        if (elecStation.getElecStationId().equals(tenantTicketStation.getElecStationId())) {
                            elecStation.setSelect("0");
                        }
                    }
                    if (map.get(elecStation.getTenantCode()) == null) {
                        ArrayList<ElecStation> list = new ArrayList<>();
                        list.add(elecStation);
                        map.put(elecStation.getTenantCode(), list);
                    } else {
                        map.get(elecStation.getTenantCode()).add(elecStation);
                    }
                }
            }
        } else {
            if (!CollectionUtils.isEmpty(hlhtTenantOpenStations)) {
                for (HlhtTenantOpenStation hlhtTenantOpenStation : hlhtTenantOpenStations) {
                    Long elecStationId = hlhtTenantOpenStation.getElecStationId();
                    ElecStation elecStation = elecStationMapper.selectByPrimaryKey(elecStationId);
                    Tenant tenant = tenantMapper.selectByPrimaryKey(elecStation.getTenantCode());
                    elecStation.setTenantName(tenant.getTenantName());
                    if (map.get(elecStation.getTenantCode()) == null) {
                        ArrayList<ElecStation> list = new ArrayList<>();
                        list.add(elecStation);
                        map.put(elecStation.getTenantCode(), list);
                    } else {
                        map.get(elecStation.getTenantCode()).add(elecStation);
                    }
                }
            }
        }
        return map;
    }

    @Override
    public Map<String, List<ElecStation>> listTicketStationExternalHlht(String tenantCode, Long ticketTypeId) {
        Map<String, List<ElecStation>> map = new HashMap<>();

        List<String> operatorIds = hlhtTenantOpenService.listOperatorIdByTenantCode(tenantCode);
        if (CollectionUtils.isEmpty(operatorIds)) {
            return null;
        }
        //所有第三方互联互通桩群
        List<ElecStation> elecStations = elecStationMapper.listStationByHlhtOperatorId(tenantCode, operatorIds);

        if (ticketTypeId != null) {
            TenantTicketStationExample tenantTicketStationExample = new TenantTicketStationExample();
            tenantTicketStationExample.createCriteria().andTicketTypeIdEqualTo(ticketTypeId);
            //已经被选的桩群
            List<TenantTicketStation> tenantTicketStations = tenantTicketStationMapper.selectByExample(tenantTicketStationExample);

            if (!CollectionUtils.isEmpty(elecStations)) {
                for (ElecStation elecStation : elecStations) {

                    //HlhtOperator hlhtOperator = hlhtOperatorService.selectByPrimaryKey(elecStation.getHlhtOperatorId());
                    //elecStation.setHlhtOperatorName(hlhtOperator.getHlhtOperatorName());
                    elecStation.setSelect("1");
                    for (TenantTicketStation tenantTicketStation : tenantTicketStations) {
                        if (elecStation.getElecStationId().equals(tenantTicketStation.getElecStationId())) {
                            elecStation.setSelect("0");
                        }
                    }
                    if (map.get(elecStation.getHlhtOperatorName()) == null) {
                        ArrayList<ElecStation> list = new ArrayList<>();
                        list.add(elecStation);
                        map.put(elecStation.getHlhtOperatorName(), list);
                    } else {
                        map.get(elecStation.getHlhtOperatorName()).add(elecStation);
                    }
                }
            }
        } else {
            if (!CollectionUtils.isEmpty(elecStations)) {
                for (ElecStation elecStation : elecStations) {
                    // HlhtOperator hlhtOperator = hlhtOperatorService.selectByPrimaryKey(elecStation.getHlhtOperatorId());
                    // elecStation.setHlhtOperatorName(hlhtOperator.getHlhtOperatorName());
                    if (map.get(elecStation.getHlhtOperatorName()) == null) {
                        ArrayList<ElecStation> list = new ArrayList<>();
                        list.add(elecStation);
                        map.put(elecStation.getHlhtOperatorName(), list);
                    } else {
                        map.get(elecStation.getHlhtOperatorName()).add(elecStation);
                    }
                }
            }
        }
        return map;
    }

    @Override
    public void insertSelectiveReturnId(ElecStation elecStation) {
        elecStationMapper.insertSelectiveReturnId(elecStation);
    }


    @Override
    public ElecStationAndCityName selectStationAndCity(Long elecStationId) {
        ElecStationAndCityName elecStationAndCityNameVo = elecStationMapper.selectStationAndCity(elecStationId);
        return elecStationAndCityNameVo;
    }


    @Override
    public void updateStatus(Long elecStationId) {
        ElecStation elecStation = elecStationMapper.selectByPrimaryKey(elecStationId);

        List<ElecPile> elecPiles = elecPileService.listPileByStationId(elecStationId);

        if ("1".equals(elecStation.getOperateStatus())) {
            changePileAndGun(elecStation, elecPiles, "2");
        } else {
            changePileAndGun(elecStation, elecPiles, "1");
        }
    }

    @Override
    public void deleteStationAndPileGun(Long elecStationId) {
        ElecStation elecStation = elecStationMapper.selectByPrimaryKey(elecStationId);
        List<ElecPile> elecPiles = elecPileService.listPileByStationId(elecStationId);
        elecStationMapper.deleteByPrimaryKey(elecStationId);
        for (ElecPile elecPile : elecPiles) {
            List<ElecGun> elecGuns = elecGunService.listGunByPileId(elecPile.getElecPileId());
            elecPileService.deleteByPrimaryKey(elecPile.getElecPileId());
            for (ElecGun elecGun : elecGuns) {
                elecGunService.deleteByPrimaryKey(elecGun.getElecGunId());
            }
        }
    }

    @Override
    public List<ElecStation> listStationBySelf(String tenantCode) {
        ElecStationExample example = new ElecStationExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode);
        List<ElecStation> elecStations = elecStationMapper.selectByExample(example);
        return elecStations;
    }

    @Override
    public String generateStationNo(Tenant tenant) {
        //int count = elecStationMapper.selectStationCount(tenant.getTenantCode());
        String stationNo = elecStationMapper.selectLastStationNo(tenant.getTenantCode());
        if (stationNo == null) {
            stationNo = tenant.getTenantPrefix() + "0001";
        }
        String format = String.format("%04d", Integer.valueOf(stationNo.substring(stationNo.length() - 4, stationNo.length())) + 1);
        return tenant.getTenantPrefix() + format;
    }

    @Override
    public String selectMostProvinceId(String tenantCode) {
        ElecStation elecStation = elecStationMapper.selectMostProvinceId(tenantCode);
        if (elecStation == null) {
            //默认返回广东
            return "440000";
        }
        if (elecStation.getProvinceId() == null || "".equals(elecStation.getProvinceId())) {
            //默认返回广东
            return "440000";
        } else {
            return elecStation.getProvinceId();
        }
    }

    @Override
    public PlatformProvince selectAllAreaByProvinceId(String provinceId) {
        PlatformProvince platformProvince = platformProvinceMapper.selectAllAreaByProvinceId(provinceId);
        return platformProvince;
    }

    @Override
    public List<ElecStation> listPrintStation(ElecSationSearch elecSationSearch) {
        List<ElecStation> elecStationResultList = elecStationMapper.listPrintStation(elecSationSearch);
        return elecStationResultList;
    }

    @Override
    public StationAllDataVo selectStationAllData(String tenantCode) {
        StationAllDataVo stationAllDataVo = elecStationMapper.selectStationAllData(tenantCode);
        return stationAllDataVo;
    }

    @Override
    public List<ElecStation> listStationAndLatiLong(String tenantCode, BaseSearch baseSearch) {
        List<ElecStation> list = elecStationMapper.listStationAndLatiLong(baseSearch);
        return list;
    }

    private void changePileAndGun(ElecStation elecStation, List<ElecPile> elecPiles, String s) {
        elecStation.setOperateStatus(s);
        elecStationMapper.updateByPrimaryKeySelective(elecStation);
        Long elecStationId = elecStation.getElecStationId();
        List<Long> elecStationIdList = new ArrayList<>();
        elecStationIdList.add(elecStationId);
        Integer status = null;
        if (BeanUtil.isValid(elecStation.getHlhtOperatorId()) && "1".equals(s)) {
            status = new Integer(1);
        }
        elecPileService.updateBatchElecPileOperateStatusByElecStationIdList(elecStationIdList, s, status);
        elecGunService.updateBatchElecGunOperateStatusByElecStationIdList(elecStationIdList, s);

    }

    @Override
    public StationAllDataVo selectStationAllDataOperator(String tenantOperatorCode) {
       /* List<Long> stationIds = elecStationMapper.listStationIdByOperator(tenantOperatorCode);
        StationAllDataVo stationAllDataVo = elecStationMapper.selectStationAllDataOperator(stationIds, tenantOperatorCode);
        return stationAllDataVo;*/
       return new StationAllDataVo();
    }

    @Override
    public List<ElecStation> selectStationAndLatiLongOperator(String tenantOperatorCode) {
        List<ElecStation> list = elecStationMapper.listStationAndLatiLongOperator(tenantOperatorCode);
        return list;
    }


    @Override
    public List<ElecStation> listByHlhtOperator(String tenantCode, String hlhtTenantCode) {
        ElecStationExample example = new ElecStationExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andHlhtOperatorIdEqualTo(hlhtTenantCode);
        List<ElecStation> elecStations = elecStationMapper.selectByExample(example);
        return elecStations;
    }

    @Override
    public PageInfo<StationHlhtTenantOpenVo> listPageStationHlhtTenantOpenInternal(StationHlhtTenantOpenSearch stationHlhtTenantOpenSearch) {
        PageHelper.startPage(stationHlhtTenantOpenSearch.getOffset(), stationHlhtTenantOpenSearch.getLimit());
        List<StationHlhtTenantOpenVo> list = elecStationMapper.listStationHlhtTenantOpenInternal(stationHlhtTenantOpenSearch);
        return new PageInfo<StationHlhtTenantOpenVo>(list);
    }

    @Override
    public ElecStation selectHlhtByOperatorAndStationNo(String tenantCode, String hlhtOperatorId, String hlhtStationNo) {
        ElecStationExample example = new ElecStationExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andHlhtOperatorIdEqualTo(hlhtOperatorId).andHlhtStationNoEqualTo(hlhtStationNo);
        List<ElecStation> list = elecStationMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(list)) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public PageInfo<StationHlhtTenantOpenVo> listPageStationHlhtTenantOpenExternal(StationHlhtTenantOpenSearch stationHlhtTenantOpenSearch) {
        PageHelper.startPage(stationHlhtTenantOpenSearch.getOffset(), stationHlhtTenantOpenSearch.getLimit());
        List<StationHlhtTenantOpenVo> list = elecStationMapper.listStationHlhtTenantOpenExternal(stationHlhtTenantOpenSearch);
        return new PageInfo<StationHlhtTenantOpenVo>(list);
    }

    @Override
    public PageInfo<HlhtTenantOpenStationVo> listPageHlhtOpenStation(HlhtTenantOpenStationSearch hlhtTenantOpenStationSearch) {
        PageHelper.startPage(hlhtTenantOpenStationSearch.getOffset(), hlhtTenantOpenStationSearch.getLimit());
        List<HlhtTenantOpenStationVo> list = elecStationMapper.listPageHlhtOpenStation(hlhtTenantOpenStationSearch);
        return new PageInfo<HlhtTenantOpenStationVo>(list);
    }

    @Override
    public PageInfo<ElecStation> listPageParkingGateStation(Integer offset, Integer limit, String tenantCode, Long parkingSupplierId, String status) {
        PageHelper.startPage(offset, limit);
        List<ElecStation> elecStationList = elecStationMapper.listParkingGateStation(tenantCode, parkingSupplierId, status);
        return new PageInfo<ElecStation>(elecStationList);
    }

    @Override
    public List<ElecStation> listElecStationNonconnectGate(String tenantCode) {
        List<ElecStation> elecStationList = elecStationMapper.listElecStationNonconnectGate(tenantCode);
        return elecStationList;
    }

    @Override
    public List<ElecStation> listByBatch(List<Long> elecStationIdList) {
        List<ElecStation> elecStationList = elecStationMapper.listByBatch(elecStationIdList);
        return elecStationList;
    }

    @Override
    public List<ElecStation> listElecStationByStationName(String tenantCode, String stationName) {
        List<ElecStation> elecStationList = elecStationMapper.listElecStationByStationName(tenantCode, stationName);
        return elecStationList;
    }

    @Override
    public PageInfo<ElecStationResult> listPageOperatorElecStaion(ElecSationSearch elecSationSearchVo) {
        PageHelper.startPage(elecSationSearchVo.getOffset(), elecSationSearchVo.getLimit());
        List<ElecStationResult> elecStationList = elecStationMapper.listOperatorElecStaion(elecSationSearchVo);
        return new PageInfo<ElecStationResult>(elecStationList);
    }

    @Override
    public PageInfo<HlhtTenantOpenStationVo> listPageHlhtStation(HlhtTenantOpenStationSearch hlhtTenantOpenStationSearch) {
        PageHelper.startPage(hlhtTenantOpenStationSearch.getOffset(), hlhtTenantOpenStationSearch.getLimit());
        List<HlhtTenantOpenStationVo> elecStationList = elecStationMapper.listPageHlhtStation(hlhtTenantOpenStationSearch);
        return new PageInfo<>(elecStationList);
    }

    @Override
    public ElecStationAndCityName selectPositiveHlhtStationAndCity(Long elecStationId) {
        ElecStationAndCityName elecStationAndCityNameVo = elecStationMapper.selectPositiveHlhtStationAndCity(elecStationId);
        return elecStationAndCityNameVo;
    }

    @Override
    public void updateBatchPositiveHlhtStation(List<Long> elecStationIdList, String operateStatus) {
        elecStationMapper.updateBatchPositiveHlhtStation(elecStationIdList, operateStatus);
    }

    @Override
    public PageInfo<ElecStation> listPageInvoiceProxyStation(InvoiceProxyStationSearchVo invoiceProxyStationSearchVO) {
        PageHelper.startPage(invoiceProxyStationSearchVO.getOffset(), invoiceProxyStationSearchVO.getLimit());
        List<ElecStation> elecStations = elecStationMapper.listPageInvoiceProxyStation(invoiceProxyStationSearchVO);
        return new PageInfo<ElecStation>(elecStations);
    }


    @Override
    public List<ElecStation> listAllStationByTenantOperatorCode(String tenantOperatorCode) {
        return elecStationMapper.listAllStationByTenantOperatorCode(tenantOperatorCode);
    }

    @Override
    public List<HlhtTenantOpenStationExportVo> listHlhtTenantOpenStation(HlhtTenantOpenStationSearch hlhtTenantOpenStationSearch) {
        return elecStationMapper.listHlhtTenantOpenStation(hlhtTenantOpenStationSearch);
    }

    @Override
    public void updateOperateStatusByHlhtTenantOpen(HlhtTenantOpen hlhtTenantOpen, String operateStatus) {
        elecStationMapper.updateOperateStatusByHlhtTenantOpen(hlhtTenantOpen, operateStatus);
    }

    @Override
    public void updateForNoTop(Long elecStationId) {
        elecStationMapper.updateForNoTop(elecStationId);
    }

    @Override
    public ElecStation selectLaststationNo() {
        return elecStationMapper.selectLaststationNo();
    }

    @Override
    public void updateSecurityStationList(List<SecurityPrevention> batteryStationIdList, List<SecurityPrevention> socStationIdList, String chargeLimitSoc, String chargeLimitBatteryTemp, String tenantCode) {
        //如果关闭清空所有运营商桩群状态
        elecStationMapper.updateSecurityStatus(tenantCode);

        TenantSetting tenantSetting = new TenantSetting();
        tenantSetting.setTenantCode(tenantCode);
        tenantSetting.setOpenChargeLimitSoc(chargeLimitSoc);
        tenantSetting.setOpenChargeLimitBatteryTemp(chargeLimitBatteryTemp);
        tenantSettingService.updateByPrimaryKeySelective(tenantSetting);

        if ("0".equals(chargeLimitSoc)) {
            for (SecurityPrevention securityPrevention : socStationIdList) {
                String[] stationId = securityPrevention.getStationId().split(",");
                elecStationMapper.updateBatchSocStatus(securityPrevention.getTemp(), stationId);
            }
        }
        if ("0".equals(chargeLimitBatteryTemp)) {
            //根据需求切割桩群
            for (SecurityPrevention securityPrevention : batteryStationIdList) {
                String[] stationId = securityPrevention.getStationId().split(",");
                elecStationMapper.updateBatchBatteryStatus(securityPrevention.getTemp(), stationId);
            }
        }
    }

    @Override
    public int countStation(StatisticsSearch search) {
        int  stationCount = elecStationMapper.countStation(search);
        return stationCount;
    }

    @Override
    public StatisticsStationNum getStatisticsStationNum(ElecSationSearch search) {
        dealRole(search);
        return elecStationMapper.getStatisticsStationNum(search);
    }
}
